package app.server.project.main.service.controller;

import app.server.project.core.constants.Def;
import app.server.project.core.http.CMSLstResp;
import app.server.project.core.http.RespModel;
import app.server.project.main.service.dto.BalanceDto;
import app.server.project.main.service.dto.CommonLuckOrderDto;
import app.server.project.main.service.dto.MyLuckOrderDto;
import app.server.project.main.service.dto.upay.AddTxReq;
import app.server.project.main.service.dto.upay.RateReq;
import app.server.project.main.service.dto.upay.USDTWithDrawReq;
import app.server.project.main.service.dto.upay.tron.TXReq;
import app.server.project.main.service.dto.upay.tron.TxDto;
import app.server.project.main.service.service.upay.BalanceService;
import app.server.project.main.service.service.upay.tron.TronAccountService;
import app.server.project.main.service.service.upay.tron.TronTransactionService;
import app.server.project.main.service.service.upay.tron.USDTRateService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


/**
 * u币模块
 */
@AllArgsConstructor
@RestController
@RequestMapping("/usdt")
public class USDTController {

    private final TronTransactionService tronTransactionService;
    private final TronAccountService tronAccountService;
    private final BalanceService balanceService;
    private final USDTRateService usdtService;

    /**
     * 获取所有TRON交易
     *
     * @param req
     * @return
     */
    @RequestMapping("/tron/getAllTx")
    public CMSLstResp<TxDto> getAllTx(TXReq req) {
        return tronTransactionService.getAllTx(req);
    }

    /**
     * 获取tron用户钱包地址
     *
     * @param userId
     * @return
     */
    @RequestMapping("/tron/getTronAddress")
    public RespModel<String> getTronAddress(@RequestHeader(Def.UserId) long userId) {
        return RespModel.success(tronAccountService.getTronAddress(userId));
    }


    /**
     * 批量激活用户钱包
     */
    @RequestMapping("/tron/batchActiveTron")
    public RespModel batchActiveTron() {
        tronAccountService.batchActiveTron();
        return RespModel.success();
    }


    /**
     * 批量转账
     */
    @RequestMapping("/tron/batchTransferTron")
    public RespModel batchTransferTron() {
        tronTransactionService.batchTransferTron();
        return RespModel.success();
    }

    /**
     * 获取用户u币余额
     *
     * @param userId
     * @return
     */
    @RequestMapping("/getBalance")
    public RespModel<BalanceDto> getBalance(@RequestHeader(Def.UserId) long userId) {
        return RespModel.success(balanceService.getBalance(userId));
    }

    /**
     * 提现
     *
     * @param req
     * @param userId
     * @return
     */
    @RequestMapping("/withdraw")
    public RespModel withdraw(@RequestBody USDTWithDrawReq req, @RequestHeader(Def.UserId) long userId) {
        balanceService.withdraw(req, userId);
        return RespModel.success();
    }

    /**
     * 人工添加u币
     *
     * @param req
     * @return
     */
    @RequestMapping("/cmsAddBalance")
    public RespModel cmsAddBalance(@RequestBody AddTxReq req) {
        balanceService.cmsAddBalance(req);
        return RespModel.success();
    }

    /**
     * 创建usdt下注订单
     *
     * @param req
     * @param userId
     * @return
     */
    @RequestMapping("/createOrder")
    public RespModel createOrder(@RequestBody RateReq req, @RequestHeader(Def.UserId) long userId) {
        usdtService.createOrder(req, userId);
        return RespModel.success();
    }

    /**
     * 获取用户所有USDT倍率-下注订单
     *
     * @param userId
     * @return
     */
    @RequestMapping("/getMyAllRateUSDT")
    public RespModel<List<MyLuckOrderDto>> getMyAllRateUSDT(@RequestHeader(Def.UserId) long userId) {
        return RespModel.success(usdtService.getMyAllRateUSDT(userId));
    }

    /**
     * 获取公共USDT倍率-下注订单
     *
     * @return
     */
    @RequestMapping("/getAllUSDTRateCommon")
    public RespModel<List<CommonLuckOrderDto>> getAllUSDTRateCommon() {
        return RespModel.success(usdtService.getAllUSDTRateCommon());
    }

}
